package com.lekang.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.lekang.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.domain.CheckInApproval;
import com.lekang.service.ICheckInApprovalService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 入住申请流程Controller
 * 
 * @author wjy
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/system/checkappeoval")
public class CheckInApprovalController extends BaseController
{
    @Autowired
    private ICheckInApprovalService checkInApprovalService;

    /**
     * 查询入住申请流程列表
     */
    @PreAuthorize("@ss.hasPermi('system:checkappeoval:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckInApproval checkInApproval)
    {
        startPage();
        List<CheckInApproval> list = checkInApprovalService.selectCheckInApprovalList(checkInApproval);
        return getDataTable(list);
    }

    /**
     * 导出入住申请流程列表
     */
    @PreAuthorize("@ss.hasPermi('system:checkappeoval:export')")
    @Log(title = "入住申请流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckInApproval checkInApproval)
    {
        List<CheckInApproval> list = checkInApprovalService.selectCheckInApprovalList(checkInApproval);
        ExcelUtil<CheckInApproval> util = new ExcelUtil<CheckInApproval>(CheckInApproval.class);
        util.exportExcel(response, list, "入住申请流程数据");
    }

    /**
     * 获取入住申请流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:checkappeoval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(checkInApprovalService.selectCheckInApprovalById(id));
    }

    /**
     * 新增入住申请流程
     */
    @PreAuthorize("@ss.hasPermi('system:checkappeoval:add')")
    @Log(title = "入住申请流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckInApproval checkInApproval)
    {
        return toAjax(checkInApprovalService.insertCheckInApproval(checkInApproval));
    }

    /**
     * 修改入住申请流程
     */
    @PreAuthorize("@ss.hasPermi('system:checkappeoval:edit')")
    @Log(title = "入住申请流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckInApproval checkInApproval)
    {
        return toAjax(checkInApprovalService.updateCheckInApproval(checkInApproval));
    }

    /**
     * 删除入住申请流程
     */
    @PreAuthorize("@ss.hasPermi('system:checkappeoval:remove')")
    @Log(title = "入住申请流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(checkInApprovalService.deleteCheckInApprovalByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('system:checkappeoval:approvedList')")
    @GetMapping("/approvedList")
    public TableDataInfo approvedList() {
        List<Map<String, Object>> list = checkInApprovalService.selectApprovedElderlyInfoList();
        return getDataTable(list);
    }

     /**
      * 查询处理类型为“申请中”的当前老人id的数量
      */
     @Anonymous
     @GetMapping("/countApprovingByElderlyId/{elderlyId}")
     public AjaxResult countApprovingByElderlyId(@PathVariable("elderlyId") Long elderlyId)
     {
        return success(checkInApprovalService.countApprovingByElderlyId(elderlyId));
     }
}
